<template>
	<view class="content">
		<view class="title">
			请进行功能选择
		</view>
		<view class="main">
			<view class="title">
				功能选择
			</view>
			<view class="funcBox">
				<view :class="item.isClick?'funcItem2':'funcItem'" v-for="item in funcList" :key="item.value"
					@click="onClickFunc(item)">
					{{ item.label }}
				</view>
			</view>
			<view class="btn">
				<button @click="handleClickBtn">确定</button>
			</view>
		</view>

<!-- 
		<uni-popup ref="popup" type="bottom" background-color="#fff"  >
			<view class="content223">
				<view class="title">
					请选择托管天数
				</view>
				<view class="itemBox">
					<view class="item" v-for="item in chooseDate" @click="handleChooseDay(item)" :key="item">
						{{item}}
					</view>
				</view>
			</view>
		</uni-popup> -->
		<uni-popup ref="popup" type="bottom" background-color="#fff" class="dialog">
			<view class="content223">
				<view class="title">
					请选择托管天数
				</view>
				<view class="itemBox">
					<view class="item" v-for="item in chooseDate" @click="handleChooseDay(item)" :key="item">
						{{item}}
					</view>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
	import {
		addTrusteeship
	} from "../../request/api";

	export default {
		data() {
			return {
				showpop:false,
				currentChoose: '',
				funcList: [{
						label: '松土',
						value: 0,
						isClick: false
					},
					{
						label: '除草',
						value: 1,
						isClick: false
					},
					{
						label: '除虫',
						value: 2,
						isClick: false
					},
					{
						label: '施肥',
						value: 3,
						isClick: false
					},
					{
						label: '浇水',
						value: 4,
						isClick: false
					},
					{
						label: '修剪',
						value: 5,
						isClick: false
					},
					{
						label: '采摘',
						value: 6,
						isClick: false
					}
				],
				chooseDate: [1, 3, 5, 7],
				opingData: {},
				landId:[]
			}
		},
		onLoad(options) {
			this.landId = JSON.parse(options.landId); // 字符串转 对象
			// console.log(this.landId)
		},
		methods: {
			onClickFunc(choose) {
				this.funcList.forEach((item, index) => {
					if (item.value === choose.value && !item.isClick) {
						item.isClick = true
					} else if (item.value === choose.value && item.isClick) {
						item.isClick = false
					}
				})
			},
			handleClickBtn() {
				let operationList = []
				this.funcList.forEach(item => {
					if (item.isClick) {
						operationList.push(item.value)
					}
				})
				if (operationList.length <= 0) {
					uni.showToast({
						title: '请选择功能',
						icon: 'none'
					})
					return
				}
				this.opingData.operationList = operationList
				this.$refs.popup.open('center')
			},
			handleChooseDay(day) {
				addTrusteeship({
					landId: this.landId,
					day,
					operationList: this.opingData.operationList
				}).then(res => {
					if (res.data.code === 200) {

						this.$refs.popup.close()
						this.funcList.forEach(item => {
							item.isClick = false
						})
						uni.switchTab({
							url:'/pages/activity/activity'
						})
						uni.showToast({
							title: '托管成功',
						})
					} else {
						uni.showToast({
							title: '未在托管有效期',
							icon: 'error'
						})
					}
				})
			}
		},

	}
</script>

<style scoped lang="less">
	.dialog {
		width: 70vw;
		height: 60vw;


		.title {
			width: 70vw;
			height: 10vw;
			background-color: rgb(0, 122, 255);
			text-align: center;
			line-height: 10vw;
			font-size: 18px;
		}

		//noinspection CssInvalidPropertyValue
		.itemBox {
			display: flex;
			margin-top: 25rpx;
			margin-bottom: 25rpx;
			justify-items: center;
			flex-wrap: wrap;

			//noinspection CssInvalidPropertyValue
			.item {
				text-align: center;
				padding-left: 10rpx;
				padding-right: 10rpx;
				margin: 15rpx;
				min-width: 80rpx;
				min-height: 50rpx;
				line-height: 50rpx;
				border: rgba(0, 0, 0) solid 1rpx;
				border-radius: 5rpx;
			}
		}
	}

	.content {
		width: 100%;
		background-color: rgb(0, 122, 255);

		>.title {
			text-align: center;
			height: 15vh;
			line-height: 15vh;
			font-weight: 600;
			font-size: 1.5em;
			color: white;
		}

		.main {
			background-color: white;
			height: 75vh;
			border-top-right-radius: 20px;
			border-top-left-radius: 20px;
			display: flex;
			flex-flow: column;
			

			.title {
				color: black;
				left: 2em;
				font-size: 16px;
				font-weight: 600;
				height: 10vh;
				line-height: 15vh;
				margin-left: 2em;
			}

			.funcBox {
				display: flex;
				flex-wrap: wrap;
				justify-content: center;
				text-align: center;
				padding-left: 10px;
				padding-right: 10px;

				.funcItem {
					display: flex;
					justify-content: center;
					margin: 1.3vw;
					width: 28vw;
					height: 8vh;
					line-height: 8vh;
					background-color: rgba(200, 200, 200, 0.3);
					border-radius: 10px;
				}

				.funcItem2 {
					display: flex;
					justify-content: center;
					margin: 1.3vw;
					width: 28vw;
					height: 8vh;
					line-height: 8vh;
					background-color: rgba(200, 200, 200, 0.7);
					color: #007aff;
					border-radius: 10px;
				}
			}

			.btn {
				position: absolute;
				bottom: 2em;
				display: flex;
				left: 50%;
				transform: translate(-50%);

				button {
					background-color: rgb(0, 122, 255);
					color: white;
					width: 30vw;
				}
			}
		}
	}
</style>
